'use strict';
layui.define(['jquery','laytpl','laypage','posts','form'], function(exports){
    let $ = layui.jquery
        ,form = layui.form
        ,posts = layui.posts;

    let obj = {
        search: '',

        pageElem: null,
        count: 0,
        limit: 0,

        box: null,
        url : '',
        tpl : '',

        pager: null,
        fields: null,

        init: function(obj){
            this.search = obj.search;
            this.fields = obj.fields;



            this.event();
            return this;
        },
        event: function(){
            let that = this;
            form.on("submit("+this.search+")", function (data) {

                that.pager.setFields(data.field).refresh();
                return false;
            });

        },
        pagination: function(obj,callback){
            let that = this;
            this.pageElem = obj.pageElem;
            this.count = obj.count;
            this.limit = obj.limit;

            this.box = obj.box;
            this.url = obj.url;
            this.tpl = obj.tpl;

            this.pager = posts.setFields(that.fields).init({
                pageElem : this.pageElem,
                count: this.count,
                limit : this.limit,

                box: this.box,
                url: this.url,
                tpl: this.tpl
            },callback);

        }

    };




    exports('search', obj);
});